var permute = function(nums) {
    let l = nums.length

    const res = []
    const curr = []
    const visited = {}

    function dfs(nth){
        if(nth === l){
            res.push([...curr])
            return
        }
        for(let i = 0; i < l; i++){
            if(!visited[nums[i]]){
                visited[nums[i]] = true
                curr.push(nums[i])
                 dfs(nth + 1)
                curr.pop()
                visited[nums[i]] = false
            }
        }
    }
    dfs(0)
    return res
};